<html>
<head>
	<meta charset="UTF-8">
	<link href="./static/assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
	<link href="./static/assets/global/css/components.css" rel="stylesheet" type="text/css"/>
	<link href="./static/assets/admin/pages/css/login.css" rel="stylesheet" type="text/css"/>
	<script src="./static/assets/global/plugins/jquery-1.11.0.min.js" type="text/javascript"></script>
	<script src="./js/common.js" type="text/javascript"></script>
</head>

<body>
<div class="content">
	<h3 class="form-title">活动列表</h3>
	<div class="table-responsive">
		<table class="table">
			<thead>
			<tr>
				<th>活动编号</th>
				<th>活动名称</th>
				<th>开始时间</th>
				<th>结束时间</th>
				<th>活动状态</th>
				<th>活动描述</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody id="container">
			</tbody>
		</table>
	</div>
</div>

</body>

<script>
	// 定义全局活动数组信息
	var g_activityList = [];
	jQuery(document).ready(function () {
		getActivityList();
	})

	//获取活动列表
	function getActivityList(){
		$.ajax({
			type:"GET",
			headers:{
				"access-token": get(common_localstorage_key)
			},
			url:"http://"+g_host+"/activity/getSeckillActivityList",
			xhrFields: {withCredentials: true},
			success:function (data) {
				if (data.code == 1001) {
					g_activityList = data.data;
					reloadDom();
				}else if (data.code == 2012){
					alert("请登录后操作")
					window.location.href = "login.html";
				}
				else {
					alert("获取活动信息失败");
				}
			},
			error:function (data) {
				alert("获取活动信息失败");
			}
		})
	}

	function reloadDom() {
		$("#container").html('')
		for (var i = 0; i < g_activityList.length; i ++){
			var itemVO = g_activityList[i];
			var dom = "<tr id='activityDetail"+ itemVO.id +"'>" +
					"<td>"+ itemVO.id +"</td>" +
					"<td>"+ itemVO.activityName +"</td>" +
					"<td>"+ itemVO.startTime +"</td>" +
					"<td>"+ itemVO.endTime +"</td>" +
					"<td>"+ getStatus(itemVO.status) +"</td>" +
					"<td>"+ itemVO.activityDesc +"</td>" +
					"<td>"+ showButton(itemVO) +"</td>" +
					"</tr>";
			$("#container").append($(dom));
		}
	}


	function showButton(itemVO){
		return "<input type='button' value='查看商品' onclick='getGoods(" + itemVO.id + ")'/>";
	}

	//查看商品
	function getGoods(activityId){
		window.location.href="goods_list.html?activityId=" + activityId;
	}

	//显示状态
	function getStatus(status){
		if (status == 0){
			return "已发布";
		}else if (status == 1){
			return "已上线";
		}else if (status == -1){
			return "已下线";
		}
	}
</script>
</html>